/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import e.odbo.data.dao.ViewDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.read.SerializerReadClass;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;

import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.query.QBFParameter;
import com.openbravo.data.loader.query.QBFParameters;
import com.openbravo.bean.erp.viewbean.TimeStoreLine_V;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class TimeStoreLine_VDAO extends ViewDAO<TimeStoreLine_V>{

    public TimeStoreLine_VDAO(I_Session s) {
        super(s);
    }

    public  List<TimeStoreLine_V> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.CUSTOMERPRICESELL, C.NAME, ATS.VALUE, T.UNITS "
                + "FROM TIMESTORELINES T LEFT  JOIN PRODUCTS P ON T.PRODUCT=P.ID LEFT OUTER JOIN CATEGORIES C ON P.CATEGORY = C.ID "
                + "LEFT OUTER JOIN  ATTRIBUTEINSTANCE ATS ON T.ATTRIBUTESETINSTANCE_ID=ATS.ID "
                + "WHERE ?(QBF_FILTER) "
                + "ORDER BY P.REFERENCE", new String[]{"T.TIMESTOREID", "T.PRODUCT", "P.CATEGORY"}), new SerializerWriteBasic(Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING), this).list(filter);
    }


    public TimeStoreLine_V readValues(DataRead dr,TimeStoreLine_V p) throws BasicException {
            if(p==null)
              p=new TimeStoreLine_V();
            p.m_ID = dr.getString(1);
            p.m_sRef = dr.getString(2);
            p.m_sCode = dr.getString(3);
            p.m_sName = dr.getString(4);
            p.m_bCom = dr.getBoolean(5).booleanValue();
            p.m_bScale = dr.getBoolean(6).booleanValue();
            p.m_dPriceBuy = dr.getDouble(7).doubleValue();
            p.m_dPriceSell = dr.getDouble(8).doubleValue();
            p.m_dCustomerPrice=dr.getDouble(9);
            p.category=dr.getString(10);
            p.attributeset=dr.getString(11);
            p.multiply=dr.getDouble(12);
            return p;
    }

    @Override
    public Class getSuportClass() {
        return TimeStoreLine_V.class;
    }

	@Override
	public List<TimeStoreLine_V> query(QBFParameters filter)
			throws BasicException {
		return  new StaticSentence(s, new QBFBuilder("SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.CUSTOMERPRICESELL, C.NAME, ATS.VALUE, T.UNITS "
                + "FROM TIMESTORELINES T LEFT  JOIN PRODUCTS P ON T.PRODUCT=P.ID LEFT OUTER JOIN CATEGORIES C ON P.CATEGORY = C.ID "
                + "LEFT OUTER JOIN  ATTRIBUTEINSTANCE ATS ON T.ATTRIBUTESETINSTANCE_ID=ATS.ID "
                + "WHERE ?(QBF_FILTER) "
                + "ORDER BY P.REFERENCE"),null,this).list(filter);
	}

	@Override
	public List<TimeStoreLine_V> query(QBFParameter filter)
			throws BasicException {
		return  new StaticSentence(s, new QBFBuilder("SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.ISCOM, P.ISSCALE, P.PRICEBUY, P.PRICESELL, P.CUSTOMERPRICESELL, C.NAME, ATS.VALUE, T.UNITS "
                + "FROM TIMESTORELINES T LEFT  JOIN PRODUCTS P ON T.PRODUCT=P.ID LEFT OUTER JOIN CATEGORIES C ON P.CATEGORY = C.ID "
                + "LEFT OUTER JOIN  ATTRIBUTEINSTANCE ATS ON T.ATTRIBUTESETINSTANCE_ID=ATS.ID "
                + "WHERE ?(QBF_FILTER) "
                + "ORDER BY P.REFERENCE"),null,this).list(filter);
	}

	
    
    
}
